<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of sougou
 *
 * @author dragon.hu add @2016.2.24
 */
require_once 'BaseChannel.php';

//搜狗
class Sougou implements BaseChannel 
{
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="{53156ABA-13A0-4DE3-B59F-BBBFCFB8F7F6}"; //payKey 
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("sougou", $_REQUEST);
		
		$gid = $_REQUEST['gid'];  //由平台分配的游戏编号
		$sid = $_REQUEST['sid'];  //由平台分配的游戏区服编号
		$uid = $_REQUEST['uid'];  //平台的用户id
		$role = $_REQUEST['role'];  //若游戏需充值到角色，传角色名。默认会传空
		$oid = $_REQUEST['oid'];  //订单号
		$date = $_REQUEST['date'];  //订单创建日期
		$amount1 = $_REQUEST['amount1'];  //用户充值金额
		$amount2 = $_REQUEST['amount2'];  //金额
		$time = $_REQUEST['time'];  //而是通知发送的时间
		$appdata = $_REQUEST['appdata'];  //透传参数
		$realAmount = $_REQUEST['realAmount'];  //用户充值真实金额
		$sign = $_REQUEST['auth'];  //验证字符串
		
		$mysign = "amount1=".$amount1."&amount2=".$amount2."&appdata=".$appdata."&date=".$date."&gid=".$gid."&oid=".$oid."&realAmount=".
				$realAmount."&role=".$role."&sid=".$sid."&time=".$time."&uid=".$uid."&".$paymentKey;
		
		if($sign == md5($mysign)) 
		{ //验证通过进行发货
			if(false == $orderLog->recordOrder(STATUS_SUCCESS, $realAmount, $appdata, "sougou", $platform,$oid))
			{
				$ret="ERR_500";
				$orderLog->log("sougou",array("order"=>$appdata,"money"=>$realAmount,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="OK";
				$orderLog->log("sougou",array("order"=>$appdata,"money"=>$realAmount,"serverresult"=>"success"));
			}
		} 
		else 
		{
			//"$sig验证失败"
			$ret = "ERR_200";
			$orderLog->log("sougou"," order:$appdata  sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}